
import { _decorator, Node } from 'cc';
import { Item_Status_Enum, Item_Type_Enum, Trigger_Status_Enum, Trigger_Type_Enum } from '../Enum';
import DataManager from '../Runtime/DataManager';
import { TriggerManager } from './TriggerManager';
const { ccclass, property } = _decorator;


@ccclass('MailboxTriggerManager')
export class MailboxTriggerManager extends TriggerManager {
    type: Trigger_Type_Enum = Trigger_Type_Enum.MailBox;

    status: Trigger_Status_Enum = Trigger_Status_Enum.Pendding;

    @property(Node)
    open: Node = null;
    @property(Node)
    close: Node = null;

    render() {
        const open: boolean = DataManager.Instance.mailBoxStatus === Trigger_Status_Enum.Resolved;
        this.open.active = open;
        this.close.active = !open;
    }

    handerClick(event) {
        const key = DataManager.Instance.items.find(i => i.type === Item_Type_Enum.Key);
        if (DataManager.Instance.isSelect && DataManager.Instance.curItemType === Item_Type_Enum.Key) {
            DataManager.Instance.mailBoxStatus = Trigger_Status_Enum.Resolved;
            DataManager.Instance.curItemType = null;
            DataManager.Instance.isSelect = false;
            key.status = Item_Status_Enum.Disabled;
            const mail = DataManager.Instance.items.find(i => i.type === Item_Type_Enum.Mail);
            mail.status = Item_Status_Enum.Scene;
            DataManager.Instance.items = [...DataManager.Instance.items]
        }
    }
}
